package org.example.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.pojo.Goods;
import org.example.pojo.Inventory;
import org.example.pojo.StockInDetail;
import org.example.pojo.StockOutVo;

@Mapper
public interface InventoryMapper {


    /**
     * 库存列表
     * @param goodsName
     * @param category
     * @return
     */
    Page<Inventory> list(String goodsName, Integer category);

    /**
     * 添加库存
     * @param inventory
     */
    void add(Inventory inventory);

    /**
     * 根据商品id查询库存
     * @param id
     * @return
     */
    @Select("select quantity from inventory where goods_id = #{id}")
    Integer getByGoodsId(Integer id);

    /**
     * 删除库存
     * @param id
     */
    @Delete("delete from inventory where goods_id = #{id}")
    void delete(Integer id);

    /**
     * 更新库存
     * @param stockInDetail
     */
    void update(StockInDetail stockInDetail);

    /**
     * 出库列表
     */
    Page<StockOutVo> stockOutList(String goodsName, String startTime, String endTime);

    /**
     * 根据商品id查询出库记录
     * @param id
     * @return
     */
    StockOutVo getStockOutByGoodsId(Integer id);

    /**
     * 出库
     * @param productId
     * @param quantity
     */
    void stockOut(Integer productId, Integer quantity);


    /**
     * 插入出库记录
     * @param stockOutVo
     */
    void addStockOut(StockOutVo stockOutVo);

    /**
     * 计算总库存数
     * @return
     */
    Integer countQuantity();

    /**
     * 库存预警
     * @return
     */
    Integer warningCount();
}
